<!DOCTYPE html>
<html lang="zh-CN">
    <head>
  <!-- 元数据 -->
  <meta charset="utf-8">
  <link rel="icon" href="/blog/images/logo.png">
  
  <title>【Java 8 新特性】时间类：ZonedDateTime | 溪岚花的博客</title>
  
  <meta name="author" content="林家隆" />
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="robots" content="index,follow" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta name="format-detection" content="telphone=no, email=no" />
  
    <meta name="keywords" content="Java" />
  
  <meta name="description" content="ZonedDateTime 是具有偏移量和时区两个概念的日期时间，由 dateTime、offset 和 zone 三个变量组成。其中 dateTime 是 LocalDateTime 类的对象，表示日期时间，offset 是 ZoneOffset 类的对象，用于表示 dateTime 对象相对于 UTC 的偏移量，zone 属于 ZoneId 类，可以是 ZoneRegion 类的对象（表示时区">
<meta property="og:type" content="article">
<meta property="og:title" content="【Java 8 新特性】时间类：ZonedDateTime">
<meta property="og:url" content="https://lin316.gitee.io/blog/2023/05/21/Java8/time/ZonedDateTime/index.html">
<meta property="og:site_name" content="溪岚花的博客">
<meta property="og:description" content="ZonedDateTime 是具有偏移量和时区两个概念的日期时间，由 dateTime、offset 和 zone 三个变量组成。其中 dateTime 是 LocalDateTime 类的对象，表示日期时间，offset 是 ZoneOffset 类的对象，用于表示 dateTime 对象相对于 UTC 的偏移量，zone 属于 ZoneId 类，可以是 ZoneRegion 类的对象（表示时区">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lin316.gitee.io/blog/blog/images/logo.png">
<meta property="article:published_time" content="2023-05-20T16:00:00.000Z">
<meta property="article:modified_time" content="2025-11-20T11:35:22.181Z">
<meta property="article:author" content="林家隆">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lin316.gitee.io/blog/blog/images/logo.png">
  
  <!-- 站点验证相关 -->
  
    
    
    
  
  <!-- 样式表文件 -->
  <link rel="stylesheet" id="kratos-css" href="/blog/css/kratosr.min.css" media="all"></script>
  
    <link rel="stylesheet" id="darkmode-css" href="/blog/css/kr-color-dark.min.css" media="(prefers-color-scheme: dark)"></script>
    <script src="/blog/js/kr-dark.min.js"></script>
  
  
    <link rel="stylesheet" id="highlight-css" href="/blog/css/highlight/night-eighties.min.css" media="all"></script>
  
  <link rel="stylesheet" id="fontawe-css" href="/blog/vendors/font-awesome@4.7.0/css/font-awesome.min.css" media="all"></script>
  <link rel="stylesheet" id="nprogress-css" href="/blog/vendors/nprogress@0.2.0/nprogress.css" media="all"></script>
  
  
  
    <link rel="stylesheet" href="/blog/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css"></script>
  
  <!-- 不得不预先加载的一些JS文件 -->
  <script src="/blog/vendors/jquery@3.6.0/dist/jquery.min.js"></script>
  
  
  <style>
    
    
  </style>
  
<meta name="generator" content="Hexo 6.3.0"></head>


    <body class="custom-background">
        <div id="kratos-wrapper">
    <div id="kratos-page">
        <div id="kratos-header">
            <header id="kratos-desktop-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="nav-header">
                        <nav id="kratos-menu-wrap">
                            <ul id="kratos-primary-menu" class="sf-menu">
                                
                                    
                                        <li>
                                            
                                                <a href="/blog/">
                                            
                                                
                                                    <i class="fa fa-home"></i>
                                                
                                                首页
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/archives/">
                                            
                                                
                                                    <i class="fa fa-file"></i>
                                                
                                                归档
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/tags/">
                                            
                                                
                                                    <i class="fa fa-tag"></i>
                                                
                                                标签
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/categories/">
                                            
                                                
                                                    <i class="fa fa-folder"></i>
                                                
                                                目录
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/search/">
                                            
                                                
                                                    <i class="fa fa-search"></i>
                                                
                                                搜索
                                            </a>
                                            
                                        </li>
                                    
                                
                            </ul>
                        </nav>
                    </div>
                </div>
            </header>
            <header id="kratos-mobile-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="color-logo"><a href="/blog/">溪岚花的博客</a></div>
                    <div class="nav-toggle">
                        <a class="kratos-nav-toggle js-kratos-nav-toggle">
                            <i></i>
                        </a>
                    </div>
                </div>
            </header>
        </div>
        <div class="kratos-start kratos-hero-2">
            <!-- <div class="kratos-overlay"></div> -->
            <div class="kratos-cover kratos-cover-2 text-center">
                <div class="desc desc2 animate-box">
                    <a href="/blog/">
                        <h2 style="opacity: 0.2;">溪岚花的博客</h2> <br />
                        <span></span>
                    </a>
                </div>
            </div>
        </div>

        <div id="kratos-blog-post">
            <div class="container">
                <div id="main" class="row">
                    

        

            <section class="col-md-8">

        

            <article itemscope itemtype="https://schema.org/Article">
    
    <link itemprop="mainEntityOfPage" href="https://lin316.gitee.io/blog/2023/05/21/Java8/time/ZonedDateTime/">
    <div class="kratos-hentry kratos-post-inner clearfix">
        <header class="kratos-entry-header">
            
                <h1 class="kratos-entry-title text-center" itemprop="name headline">【Java 8 新特性】时间类：ZonedDateTime</h1>
            
            
            <ul class="kratos-post-meta text-center">
                <li><time datetime="2023-05-20T16:00:00.000Z" itemprop="datePublished"><i class="fa fa-calendar"></i> 2023-05-21</time></li>
                <li itemprop="author" itemscope itemtype="https://schema.org/Person">
                    <i class="fa fa-user"></i> 作者 <span itemprop="name">林家隆</span>
                </li>
                
                    <li>
                        <i class="fa fa-edit"></i> 
                        
                        
                            12.89K
                        
                        字
                    </li>
                
                
            </ul>
        </header>
        <div class="kratos-post-content">
            
            <div id="expire-alert" class="alert alert-warning hidden" role="alert">
                <div class="icon"><i class="fa fa-warning"></i></div>
                <div class="text"><p>本文最后编辑于 <time datetime="1763638522181"></time> 前，其中的内容可能需要更新。</p></div>
            </div>
            
            
            
                <div class="kratos-post-inner-toc toc-div-class" >
                    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="toc-number">1.</span> <span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal"><span class="toc-number">1.1.</span> <span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now"><span class="toc-number">1.2.</span> <span class="toc-text">now()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-ZoneId-zone"><span class="toc-number">1.3.</span> <span class="toc-text">now(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-Clock-clock"><span class="toc-number">1.4.</span> <span class="toc-text">now(Clock clock)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-int-year-int-month-int-dayOfMonth-int-hour-int-minute-int-second-int-nanoOfSecond-ZoneId-zone"><span class="toc-number">1.5.</span> <span class="toc-text">of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-LocalDate-date-LocalTime-time-ZoneId-zone"><span class="toc-number">1.6.</span> <span class="toc-text">of(LocalDate date, LocalTime time, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-LocalDateTime-localDateTime-ZoneId-zone"><span class="toc-number">1.7.</span> <span class="toc-text">of(LocalDateTime localDateTime, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofInstant-Instant-instant-ZoneId-zone"><span class="toc-number">1.8.</span> <span class="toc-text">ofInstant(Instant instant, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofInstant-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone"><span class="toc-number">1.9.</span> <span class="toc-text">ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofLocal-LocalDateTime-localDateTime-ZoneId-zone-ZoneOffset-preferredOffset"><span class="toc-number">1.10.</span> <span class="toc-text">ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofStrict-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone"><span class="toc-number">1.11.</span> <span class="toc-text">ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text"><span class="toc-number">1.12.</span> <span class="toc-text">parse(CharSequence text)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text-DateTimeFormatter-formatter"><span class="toc-number">1.13.</span> <span class="toc-text">parse(CharSequence text, DateTimeFormatter formatter)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-number">2.</span> <span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#format-DateTimeFormatter-formatter"><span class="toc-number">2.1.</span> <span class="toc-text">format(DateTimeFormatter formatter)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getZone"><span class="toc-number">2.2.</span> <span class="toc-text">getZone()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toLocalDate"><span class="toc-number">2.3.</span> <span class="toc-text">toLocalDate()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toLocalDateTime"><span class="toc-number">2.4.</span> <span class="toc-text">toLocalDateTime()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toLocalTime"><span class="toc-number">2.5.</span> <span class="toc-text">toLocalTime()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toOffsetDateTime"><span class="toc-number">2.6.</span> <span class="toc-text">toOffsetDateTime()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#truncatedTo-TemporalUnit-unit"><span class="toc-number">2.7.</span> <span class="toc-text">truncatedTo(TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#until-Temporal-endExclusive-TemporalUnit-unit"><span class="toc-number">2.8.</span> <span class="toc-text">until(Temporal endExclusive, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withEarlierOffsetAtOverlap"><span class="toc-number">2.9.</span> <span class="toc-text">withEarlierOffsetAtOverlap()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withLaterOffsetAtOverlap"><span class="toc-number">2.10.</span> <span class="toc-text">withLaterOffsetAtOverlap()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withFixedOffsetZone"><span class="toc-number">2.11.</span> <span class="toc-text">withFixedOffsetZone()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withZoneSameInstant-ZoneId-zone"><span class="toc-number">2.12.</span> <span class="toc-text">withZoneSameInstant(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withZoneSameLocal-ZoneId-zone"><span class="toc-number">2.13.</span> <span class="toc-text">withZoneSameLocal(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95"><span class="toc-number">2.14.</span> <span class="toc-text">未演示方法</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="toc-number">3.</span> <span class="toc-text">参考文献</span></a></li></ol>
                </div>
            
            <hr />
            <div itemprop="articleBody"><p>ZonedDateTime 是具有偏移量和时区两个概念的日期时间，由 dateTime、offset 和 zone 三个变量组成。其中 dateTime 是 LocalDateTime 类的对象，表示日期时间，offset 是 ZoneOffset 类的对象，用于表示 dateTime 对象相对于 UTC 的偏移量，zone 属于 ZoneId 类，可以是 ZoneRegion 类的对象（表示时区），也可以是 ZoneOffset，此时没有时区的概念。ZonedDateTime 在功能上跟 OffsetDateTime 差不多，但 ZonedDateTime 在时区转换上使用起来跟方便。</p>
<h3 id="静态方法"><a href="#静态方法" class="headerlink" title="静态方法"></a>静态方法</h3><h4 id="from-TemporalAccessor-temporal"><a href="#from-TemporalAccessor-temporal" class="headerlink" title="from(TemporalAccessor temporal)"></a>from(TemporalAccessor temporal)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* from(TemporalAccessor temporal)</span></span><br><span class="line"><span class="comment">* 作用：从其他具有偏移量或时区概念的时间对象获取 zonedDateTime 对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">OffsetDateTime</span> <span class="variable">offsetDateTime01</span> <span class="operator">=</span> OffsetDateTime.parse(<span class="string">&quot;1970-01-01T08:00:00+08:00&quot;</span>); <span class="comment">// UTC时间 1970-01-01T00:00:00</span></span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.from(offsetDateTime01);</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 1970-01-01T08:00+08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="now"><a href="#now" class="headerlink" title="now()"></a>now()</h4><h4 id="now-ZoneId-zone"><a href="#now-ZoneId-zone" class="headerlink" title="now(ZoneId zone)"></a>now(ZoneId zone)</h4><h4 id="now-Clock-clock"><a href="#now-Clock-clock" class="headerlink" title="now(Clock clock)"></a>now(Clock clock)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* now()</span></span><br><span class="line"><span class="comment">* 作用：从操作系统获取 zonedDateTime 对象。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* now(ZoneId zone)</span></span><br><span class="line"><span class="comment">* 作用：获取指定时区此刻的日期时间。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* now(Clock clock)</span></span><br><span class="line"><span class="comment">* 作用：从 clock 对象获取 zonedDateTime 对象。clock 对象有时区的概念，</span></span><br><span class="line"><span class="comment">*      获取的是 clock 对象指定时区的日期时间。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;America/Los_Angeles&quot;</span>);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.now();</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 2023-05-02T22:39:07.435788600+08:00[Asia/Shanghai]</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime02</span> <span class="operator">=</span> ZonedDateTime.now(zoneId01);</span><br><span class="line">    System.out.println(zonedDateTime02); <span class="comment">// 输出 2023-05-02T07:39:07.435788600-07:00[America/Los_Angeles]</span></span><br><span class="line"></span><br><span class="line">    <span class="type">Instant</span> <span class="variable">instant01</span> <span class="operator">=</span> Instant.parse(<span class="string">&quot;2023-04-01T10:00:00Z&quot;</span>);</span><br><span class="line">    <span class="type">Clock</span> <span class="variable">fixedClock01</span> <span class="operator">=</span> Clock.fixed(instant01, zoneId01);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime03</span> <span class="operator">=</span> ZonedDateTime.now(fixedClock01);</span><br><span class="line">    System.out.println(zonedDateTime03); <span class="comment">// 输出 2023-04-01T03:00-07:00[America/Los_Angeles]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="of-int-year-int-month-int-dayOfMonth-int-hour-int-minute-int-second-int-nanoOfSecond-ZoneId-zone"><a href="#of-int-year-int-month-int-dayOfMonth-int-hour-int-minute-int-second-int-nanoOfSecond-ZoneId-zone" class="headerlink" title="of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)"></a>of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)</h4><h4 id="of-LocalDate-date-LocalTime-time-ZoneId-zone"><a href="#of-LocalDate-date-LocalTime-time-ZoneId-zone" class="headerlink" title="of(LocalDate date, LocalTime time, ZoneId zone)"></a>of(LocalDate date, LocalTime time, ZoneId zone)</h4><h4 id="of-LocalDateTime-localDateTime-ZoneId-zone"><a href="#of-LocalDateTime-localDateTime-ZoneId-zone" class="headerlink" title="of(LocalDateTime localDateTime, ZoneId zone)"></a>of(LocalDateTime localDateTime, ZoneId zone)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)</span></span><br><span class="line"><span class="comment"> * of(LocalDate date, LocalTime time, ZoneId zone)</span></span><br><span class="line"><span class="comment"> * of(LocalDateTime localDateTime, ZoneId zone)</span></span><br><span class="line"><span class="comment"> * 作用：给定日期时间和地区/偏移量数据，创建 zonedDateTime 对象。</span></span><br><span class="line"><span class="comment"> *      dateTime和zone只是组合关系。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test03</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">LocalDateTime</span> <span class="variable">localDateTime01</span> <span class="operator">=</span> LocalDateTime.parse(<span class="string">&quot;2023-01-01T00:00:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneRegion01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;Asia/Shanghai&quot;</span>);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.of(localDateTime01, zoneRegion01);</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 2023-01-01T00:00+08:00[Asia/Shanghai]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="ofInstant-Instant-instant-ZoneId-zone"><a href="#ofInstant-Instant-instant-ZoneId-zone" class="headerlink" title="ofInstant(Instant instant, ZoneId zone)"></a>ofInstant(Instant instant, ZoneId zone)</h4><h4 id="ofInstant-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone"><a href="#ofInstant-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone" class="headerlink" title="ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)"></a>ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * ofInstant(Instant instant, ZoneId zone)</span></span><br><span class="line"><span class="comment"> * 作用：instant 是 UTC 时间轴上的一个瞬时值，被当成 UTC 时间来看待。</span></span><br><span class="line"><span class="comment"> *      该方法会将 instant 时间转换成对应时区的时间。</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</span></span><br><span class="line"><span class="comment"> * 作用：如果 zone 和 offset 匹配，那么 localDateTime、offset 和 zone 只是组合关系。</span></span><br><span class="line"><span class="comment"> *      如果不匹配，那么 localDateTime 会根据 offset 偏移量转成 UTC 时间，然后再转成对应的时区的时间。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test04</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">LocalDateTime</span> <span class="variable">localDateTime01</span> <span class="operator">=</span> LocalDateTime.parse(<span class="string">&quot;2023-01-01T00:00:00&quot;</span>);</span><br><span class="line">    <span class="type">Instant</span> <span class="variable">instant01</span> <span class="operator">=</span> Instant.ofEpochSecond(<span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneRegion01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;Asia/Shanghai&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset02</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+10:00&quot;</span>);</span><br><span class="line"></span><br><span class="line">    System.out.println(instant01); <span class="comment">// 输出 1970-01-01T00:00:00Z</span></span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.ofInstant(instant01, zoneRegion01);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime02</span> <span class="operator">=</span> ZonedDateTime.ofInstant(instant01, zoneOffset02);</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 1970-01-01T08:00+08:00[Asia/Shanghai]</span></span><br><span class="line">    System.out.println(zonedDateTime02); <span class="comment">// 输出 1970-01-01T10:00+10:00</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime03</span> <span class="operator">=</span> ZonedDateTime.ofInstant(localDateTime01, zoneOffset01, zoneRegion01);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime04</span> <span class="operator">=</span> ZonedDateTime.ofInstant(localDateTime01, zoneOffset02, zoneRegion01);</span><br><span class="line">    System.out.println(zonedDateTime03); <span class="comment">// 输出 2023-01-01T00:00+08:00[Asia/Shanghai]</span></span><br><span class="line">    System.out.println(zonedDateTime04); <span class="comment">// 输出 2022-12-31T22:00+08:00[Asia/Shanghai]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="ofLocal-LocalDateTime-localDateTime-ZoneId-zone-ZoneOffset-preferredOffset"><a href="#ofLocal-LocalDateTime-localDateTime-ZoneId-zone-ZoneOffset-preferredOffset" class="headerlink" title="ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)"></a>ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)</h4><h4 id="ofStrict-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone"><a href="#ofStrict-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone" class="headerlink" title="ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)"></a>ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)</span></span><br><span class="line"><span class="comment"> * 作用：作用跟 of(LocalDateTime localDateTime, ZoneId zone) 类似，dateTime 和 zone 只是组合关系。</span></span><br><span class="line"><span class="comment"> *      不同的是某些时区在特殊时间段跟 UTC 会有多个的时差。preferredOffset 用来指定使用哪个时差，</span></span><br><span class="line"><span class="comment"> *      如果为 null 默认选择第一个时差。例如美国洛杉矶时间分夏令时和冬令时，夏令时比 UTC 慢 7 小时，</span></span><br><span class="line"><span class="comment"> *      冬令时比 UTC 慢 8 小时，在夏令时转冬令时的特殊时间段跟 UTC 有两个时差，分别是 -07:00 和 -08:00 。</span></span><br><span class="line"><span class="comment"> *      preferredOffset 对象用来确定使用哪个时差。</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</span></span><br><span class="line"><span class="comment"> * 作用：作用跟 ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)方法类似，</span></span><br><span class="line"><span class="comment"> *      不同的是 ofStrict() 方法会严格校验偏移量和区域的组合，如果不匹配会报错，不像 ofInstant() 方法会另外处理。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test05</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">LocalDateTime</span> <span class="variable">localDateTime01</span> <span class="operator">=</span> LocalDateTime.parse(<span class="string">&quot;2023-01-01T00:00:00&quot;</span>);</span><br><span class="line">    <span class="type">LocalDateTime</span> <span class="variable">localDateTime02</span> <span class="operator">=</span> LocalDateTime.parse(<span class="string">&quot;2023-11-05T01:00:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneRegion01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;Asia/Shanghai&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneRegion02</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;America/Los_Angeles&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset01</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+08:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset02</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;+10:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset03</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;-08:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneOffset</span> <span class="variable">zoneOffset04</span> <span class="operator">=</span> ZoneOffset.of(<span class="string">&quot;-07:00&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.ofLocal(localDateTime02, zoneRegion02, zoneOffset03);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime02</span> <span class="operator">=</span> ZonedDateTime.ofLocal(localDateTime02, zoneRegion02, zoneOffset04);</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 2023-11-05T01:00-08:00[America/Los_Angeles]</span></span><br><span class="line">    System.out.println(zonedDateTime02); <span class="comment">// 输出 2023-11-05T01:00-07:00[America/Los_Angeles]</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime03</span> <span class="operator">=</span> ZonedDateTime.ofStrict(localDateTime01, zoneOffset01, zoneRegion01);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime04</span> <span class="operator">=</span> ZonedDateTime.ofStrict(localDateTime01, zoneOffset02, zoneRegion01);</span><br><span class="line">    System.out.println(zonedDateTime03); <span class="comment">// 输出 2023-01-01T00:00+08:00[Asia/Shanghai]</span></span><br><span class="line">    System.out.println(zonedDateTime04); <span class="comment">// 报错 java.time.DateTimeException: ZoneOffset &#x27;+10:00&#x27; is not valid for LocalDateTime &#x27;2023-01-01T00:00&#x27; in zone &#x27;Asia/Shanghai&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="parse-CharSequence-text"><a href="#parse-CharSequence-text" class="headerlink" title="parse(CharSequence text)"></a>parse(CharSequence text)</h4><h4 id="parse-CharSequence-text-DateTimeFormatter-formatter"><a href="#parse-CharSequence-text-DateTimeFormatter-formatter" class="headerlink" title="parse(CharSequence text, DateTimeFormatter formatter)"></a>parse(CharSequence text, DateTimeFormatter formatter)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * parse(CharSequence text)</span></span><br><span class="line"><span class="comment"> * parse(CharSequence text, DateTimeFormatter formatter)</span></span><br><span class="line"><span class="comment"> * 作用：将字符串解析成 zonedDateTime 对象，默认格式 yyyy-MM-ddTHH:mm:ssxxx&#x27;[&#x27;VV&#x27;]&#x27;，</span></span><br><span class="line"><span class="comment"> *      其中 xxx 表示偏移量，[VV] 表示时区，formatter 用来指定字符串格式。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test06</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;2023-01-01T12:00:00+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 2023-01-01T12:00+08:00[Asia/Shanghai]</span></span><br><span class="line"></span><br><span class="line">    <span class="type">DateTimeFormatter</span> <span class="variable">df01</span> <span class="operator">=</span> DateTimeFormatter.ofPattern(<span class="string">&quot;yyyyMMdd HH:mm:ssxxx &#x27;[&#x27;VV&#x27;]&#x27;&quot;</span>);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime02</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;20230101 12:00:00+08:00 [Asia/Shanghai]&quot;</span>, df01);</span><br><span class="line">    System.out.println(zonedDateTime02); <span class="comment">// 输出 2023-01-01T12:00+08:00[Asia/Shanghai]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<br>

<h3 id="成员方法"><a href="#成员方法" class="headerlink" title="成员方法"></a>成员方法</h3><h4 id="format-DateTimeFormatter-formatter"><a href="#format-DateTimeFormatter-formatter" class="headerlink" title="format(DateTimeFormatter formatter)"></a>format(DateTimeFormatter formatter)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * format(DateTimeFormatter formatter)</span></span><br><span class="line"><span class="comment"> * 作用：将 zonedDateTime 对象按指定格式输出。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">DateTimeFormatter</span> <span class="variable">df01</span> <span class="operator">=</span> DateTimeFormatter.ofPattern(<span class="string">&quot;yyyy/MM/dd HH:ss:dd 偏移量：xxx 时区：&#x27;[&#x27;VV&#x27;]&#x27;&quot;</span>);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;2023-01-01T12:00:00+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    System.out.println(dateTime01); <span class="comment">// 输出 2023-01-01T12:00+08:00[Asia/Shanghai]</span></span><br><span class="line">    System.out.println(dateTime01.format(df01)); <span class="comment">// 输出 2023/01/01 12:00:01 偏移量：+08:00 时区：[Asia/Shanghai]（不知道为什么结果多了一秒）</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getZone"><a href="#getZone" class="headerlink" title="getZone()"></a>getZone()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * getZone()</span></span><br><span class="line"><span class="comment"> * 作用：获取时区对象。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;1970-01-01T08:00:00+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId</span> <span class="operator">=</span> dateTime01.getZone();</span><br><span class="line">    System.out.println(zoneId); <span class="comment">// 输出 Asia/Shanghai</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="toLocalDate"><a href="#toLocalDate" class="headerlink" title="toLocalDate()"></a>toLocalDate()</h4><h4 id="toLocalDateTime"><a href="#toLocalDateTime" class="headerlink" title="toLocalDateTime()"></a>toLocalDateTime()</h4><h4 id="toLocalTime"><a href="#toLocalTime" class="headerlink" title="toLocalTime()"></a>toLocalTime()</h4><h4 id="toOffsetDateTime"><a href="#toOffsetDateTime" class="headerlink" title="toOffsetDateTime()"></a>toOffsetDateTime()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * toLocalDate()</span></span><br><span class="line"><span class="comment"> * toLocalDateTime()</span></span><br><span class="line"><span class="comment"> * toLocalTime()</span></span><br><span class="line"><span class="comment"> * toOffsetDateTime()</span></span><br><span class="line"><span class="comment"> * 作用：见名知意，通过 zonedDateTime 对象获取其他时间类对象。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test03</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;1970-01-01T08:00:00+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    System.out.println(dateTime01.toLocalDate()); <span class="comment">// 输出 1970-01-01</span></span><br><span class="line">    System.out.println(dateTime01.toLocalTime()); <span class="comment">// 输出 08:00</span></span><br><span class="line">    System.out.println(dateTime01.toOffsetDateTime()); <span class="comment">// 输出 1970-01-01T08:00+08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="truncatedTo-TemporalUnit-unit"><a href="#truncatedTo-TemporalUnit-unit" class="headerlink" title="truncatedTo(TemporalUnit unit)"></a>truncatedTo(TemporalUnit unit)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * truncatedTo(TemporalUnit unit)</span></span><br><span class="line"><span class="comment"> * 作用：根据时间单位截取 zonedDateTime 对象。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test04</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;1970-01-01T12:30:45+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    System.out.println(dateTime01); <span class="comment">// 输出 1970-01-01T12:30:45+08:00[Asia/Shanghai]</span></span><br><span class="line">    System.out.println(dateTime01.truncatedTo(ChronoUnit.MINUTES)); <span class="comment">// 输出 1970-01-01T12:30+08:00[Asia/Shanghai]</span></span><br><span class="line">    System.out.println(dateTime01.truncatedTo(ChronoUnit.HOURS)); <span class="comment">// 输出 1970-01-01T12:00+08:00[Asia/Shanghai]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="until-Temporal-endExclusive-TemporalUnit-unit"><a href="#until-Temporal-endExclusive-TemporalUnit-unit" class="headerlink" title="until(Temporal endExclusive, TemporalUnit unit)"></a>until(Temporal endExclusive, TemporalUnit unit)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * until(Temporal endExclusive, TemporalUnit unit)</span></span><br><span class="line"><span class="comment"> * 作用：根据指定的时间单位计算两个 zonedDateTime 对象的差值。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test05</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;1970-01-01T00:00:00+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">dateTime02</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;1970-01-01T01:00:00+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    System.out.println(dateTime01.until(dateTime02, ChronoUnit.HOURS)); <span class="comment">// 输出 1</span></span><br><span class="line">    System.out.println(dateTime01.until(dateTime02, ChronoUnit.MINUTES)); <span class="comment">// 输出 60</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="withEarlierOffsetAtOverlap"><a href="#withEarlierOffsetAtOverlap" class="headerlink" title="withEarlierOffsetAtOverlap()"></a>withEarlierOffsetAtOverlap()</h4><h4 id="withLaterOffsetAtOverlap"><a href="#withLaterOffsetAtOverlap" class="headerlink" title="withLaterOffsetAtOverlap()"></a>withLaterOffsetAtOverlap()</h4><h4 id="withFixedOffsetZone"><a href="#withFixedOffsetZone" class="headerlink" title="withFixedOffsetZone()"></a>withFixedOffsetZone()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * withEarlierOffsetAtOverlap()</span></span><br><span class="line"><span class="comment"> * withLaterOffsetAtOverlap()</span></span><br><span class="line"><span class="comment"> * 作用：由于夏令时等因素，同一时区在某段时间内会出现两个不同的偏移量。</span></span><br><span class="line"><span class="comment"> *      以上方法用来解决二义性的问题，调用以上方法用来确认使用哪个偏移量。</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * withFixedOffsetZone()</span></span><br><span class="line"><span class="comment"> * 作用：调整为只带偏移量，不带时区概念的 zonedDateTime 对象，</span></span><br><span class="line"><span class="comment"> *      可以忽略时区带来夏令时等因素的影响。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test06</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">LocalDateTime</span> <span class="variable">localDateTime01</span> <span class="operator">=</span> LocalDateTime.parse(<span class="string">&quot;2023-11-05T01:00:00&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;America/Los_Angeles&quot;</span>);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> ZonedDateTime.of(localDateTime01, zoneId);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime02</span> <span class="operator">=</span> zonedDateTime01.withLaterOffsetAtOverlap();</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 2023-11-05T01:00-07:00[America/Los_Angeles]</span></span><br><span class="line">    System.out.println(zonedDateTime02); <span class="comment">// 输出 2023-11-05T01:00-08:00[America/Los_Angeles]</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zoneddateTime03</span> <span class="operator">=</span> zonedDateTime01.withFixedOffsetZone();</span><br><span class="line">    System.out.println(zoneddateTime03); <span class="comment">// 输出 2023-11-05T01:00-07:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="withZoneSameInstant-ZoneId-zone"><a href="#withZoneSameInstant-ZoneId-zone" class="headerlink" title="withZoneSameInstant(ZoneId zone)"></a>withZoneSameInstant(ZoneId zone)</h4><h4 id="withZoneSameLocal-ZoneId-zone"><a href="#withZoneSameLocal-ZoneId-zone" class="headerlink" title="withZoneSameLocal(ZoneId zone)"></a>withZoneSameLocal(ZoneId zone)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * withZoneSameInstant(ZoneId zone)</span></span><br><span class="line"><span class="comment"> * 作用：通过调整时区或偏移量来调整 zonedDateTime 对象，</span></span><br><span class="line"><span class="comment"> *      但不管如何调整，转换成的 UTC 时间不变。</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * withZoneSameLocal(ZoneId zone)</span></span><br><span class="line"><span class="comment"> * 作用：时间不变，仅改变时区或偏移量。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test07</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> ZonedDateTime.parse(<span class="string">&quot;2023-01-01T16:00:00+08:00[Asia/Shanghai]&quot;</span>);</span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;America/Los_Angeles&quot;</span>);</span><br><span class="line">    System.out.println(dateTime01.withZoneSameInstant(zoneId01)); <span class="comment">// 输出 2023-01-01T00:00-08:00[America/Los_Angeles]</span></span><br><span class="line">    System.out.println(dateTime01.withZoneSameLocal(zoneId01)); <span class="comment">// 输出 2023-01-01T16:00-08:00[America/Los_Angeles]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="未演示方法"><a href="#未演示方法" class="headerlink" title="未演示方法"></a>未演示方法</h4><p>以下方法大多在 <code>LocalDate</code> 和 <code>LocalTime</code> 篇章演示过且作用类似，该篇章就不在赘述了。</p>
<ol>
<li>equals(Object obj)</li>
<li>get(TemporalField field)</li>
<li>getLong(TemporalField field)</li>
<li>getDayOfMonth()</li>
<li>getDayOfWeek()</li>
<li>getDayOfYear()</li>
<li>getYear()</li>
<li>getMonth()</li>
<li>getMonthValue()</li>
<li>getHour()</li>
<li>getMinute()</li>
<li>getNano()</li>
<li>getOffset()</li>
<li>getSecond()</li>
<li>hashCode()</li>
<li>isSupported(TemporalField field)</li>
<li>isSupported(TemporalUnit unit)</li>
<li>minus(long amountToSubtract, TemporalUnit unit)</li>
<li>minus(TemporalAmount amountToSubtract)</li>
<li>minusDays(long days)</li>
<li>minusMonths(long months)</li>
<li>minusWeeks(long weeks)</li>
<li>minusYears(long years)</li>
<li>minusHours(long hours)</li>
<li>minusMinutes(long minutes)</li>
<li>minusNanos(long nanos)</li>
<li>minusSeconds(long seconds)</li>
<li>plus(long amountToAdd, TemporalUnit unit)</li>
<li>plus(TemporalAmount amountToAdd)</li>
<li>plusDays(long days)</li>
<li>plusMonths(long months)</li>
<li>plusWeeks(long weeks)</li>
<li>plusYears(long years)</li>
<li>plusHours(long hours)</li>
<li>plusMinutes(long minutes)</li>
<li>plusNanos(long nanos)</li>
<li>plusSeconds(long seconds)</li>
<li>query(TemporalQuery<R> query)</R></li>
<li>range(TemporalField field)</li>
<li>toString()</li>
<li>with(TemporalAdjuster adjuster)</li>
<li>with(TemporalField field, long newValue)</li>
<li>withDayOfMonth(int dayOfMonth)</li>
<li>withDayOfYear(int dayOfYear)</li>
<li>withMonth(int month)</li>
<li>withYear(int year)</li>
<li>withHour(int hour)</li>
<li>withMinute(int minute)</li>
<li>withNano(int nanoOfSecond)</li>
<li>withSecond(int second)</li>
</ol>
<h3 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h3><p><a target="_blank" rel="noopener" href="https://www.matools.com/api/java8">https://www.matools.com/api/java8</a></p>
</div>
        </div>
        
        <footer class="kratos-entry-footer clearfix">
            
            <div class="footer-tag clearfix">
                <div class="pull-left">
                <i class="fa fa-tags"></i>
                    <a class="tag-none-link" href="/blog/tags/Java/" rel="tag">Java</a>
                </div>
                <div class="pull-date">
                    <time datetime="2025-11-20T11:35:22.181Z" itemprop="dateModified">最后编辑：2025-11-20</time>
                </div>
            </div>
        </footer>
    </div>
    
        <nav class="navigation post-navigation clearfix" role="navigation">
            
            <div class="nav-previous clearfix">
                <a title=" MySQL 中的数据类型" href="/blog/2023/05/17/mysql/数据类型/">&lt; 上一篇</a>
            </div>
            
            
            <div class="nav-next clearfix">
                <a title=" 【Java 8 新特性】时间类：OffsetTime 和 OffsetDateTime" href="/blog/2023/05/21/Java8/time/OffsetTime_OffsetDateTime/">下一篇 &gt;</a>
            </div>
            
        </nav>
    
    
</article>

        

            </section>

        

                
            

<section id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm">
    <!-- 文章和页面根据splitter来分割，没有的话就从头开始设置为sticky -->
    
    
                <aside id="krw-about" class="widget widget-kratos-about clearfix">
    <div class="photo-background"></div>
    <div class="photo-wrapper clearfix">
        <div class="photo-wrapper-tip text-center">
            <img class="about-photo" src="/blog/images/avatar.webp" loading="lazy" decoding="auto" />
        </div>
    </div>
    <div class="textwidget">
        <p class="text-center">极简主义</p>
    </div>
    <div class="site-meta">
        <a class="meta-item" href="/blog/archives/">
            <span class="title">
                文章
            </span>
            <span class="count">
                72
            </span>
        </a>
        <a class="meta-item" href="/blog/categories/">
            <span class="title">
                分类
            </span>
            <span class="count">
                9
            </span>
        </a>
        <a class="meta-item" href="/blog/tags/">
            <span class="title">
                标签
            </span>
            <span class="count">
                27
            </span>
        </a>
    </div>
</aside>
            
                    <div class="sticky-area">
                
                    <aside id="krw-toc" class="widget widget-kratos-toc clearfix toc-div-class" >
    <div class="photo-background"></div>
    <h4 class="widget-title no-after">
        <i class="fa fa-compass"></i>
        文章目录
        <span class="toc-progress-bar" role="progressbar" aria-label="阅读进度："></span>
    </h4>
    <div class="textwidget">
        <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal"><span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now"><span class="toc-text">now()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-ZoneId-zone"><span class="toc-text">now(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-Clock-clock"><span class="toc-text">now(Clock clock)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-int-year-int-month-int-dayOfMonth-int-hour-int-minute-int-second-int-nanoOfSecond-ZoneId-zone"><span class="toc-text">of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-LocalDate-date-LocalTime-time-ZoneId-zone"><span class="toc-text">of(LocalDate date, LocalTime time, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-LocalDateTime-localDateTime-ZoneId-zone"><span class="toc-text">of(LocalDateTime localDateTime, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofInstant-Instant-instant-ZoneId-zone"><span class="toc-text">ofInstant(Instant instant, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofInstant-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone"><span class="toc-text">ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofLocal-LocalDateTime-localDateTime-ZoneId-zone-ZoneOffset-preferredOffset"><span class="toc-text">ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofStrict-LocalDateTime-localDateTime-ZoneOffset-offset-ZoneId-zone"><span class="toc-text">ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text"><span class="toc-text">parse(CharSequence text)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text-DateTimeFormatter-formatter"><span class="toc-text">parse(CharSequence text, DateTimeFormatter formatter)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#format-DateTimeFormatter-formatter"><span class="toc-text">format(DateTimeFormatter formatter)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getZone"><span class="toc-text">getZone()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toLocalDate"><span class="toc-text">toLocalDate()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toLocalDateTime"><span class="toc-text">toLocalDateTime()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toLocalTime"><span class="toc-text">toLocalTime()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toOffsetDateTime"><span class="toc-text">toOffsetDateTime()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#truncatedTo-TemporalUnit-unit"><span class="toc-text">truncatedTo(TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#until-Temporal-endExclusive-TemporalUnit-unit"><span class="toc-text">until(Temporal endExclusive, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withEarlierOffsetAtOverlap"><span class="toc-text">withEarlierOffsetAtOverlap()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withLaterOffsetAtOverlap"><span class="toc-text">withLaterOffsetAtOverlap()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withFixedOffsetZone"><span class="toc-text">withFixedOffsetZone()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withZoneSameInstant-ZoneId-zone"><span class="toc-text">withZoneSameInstant(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withZoneSameLocal-ZoneId-zone"><span class="toc-text">withZoneSameLocal(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95"><span class="toc-text">未演示方法</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="toc-text">参考文献</span></a></li></ol>
    </div>
</aside>
                
                
  <aside id="krw-categories" class="widget widget-kratos-categories clearfix">
    <h4 class="widget-title"><i class="fa fa-folder"></i>分类目录</h4>
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Docker/">Docker</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Idea/">Idea</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java/">Java</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Linux/">Linux</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/MySQL/">MySQL</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Python/">Python</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Selenium/">Selenium</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SpringBoot/">SpringBoot</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SpringCloud/">SpringCloud</a><span class="category-list-count">13</span></li></ul>
  </aside>


            
                
  <aside id="krw-tags" class="widget widget-kratos-tags clearfix">
    <h4 class="widget-title"><i class="fa fa-tags"></i>标签聚合</h4>
      <div class="tag-clouds">
        <a href="/blog/tags/CORS/" style="font-size: 0.8em;">CORS</a> <a href="/blog/tags/Docker/" style="font-size: 0.8em;">Docker</a> <a href="/blog/tags/Dubbo/" style="font-size: 0.8em;">Dubbo</a> <a href="/blog/tags/ELK/" style="font-size: 0.8em;">ELK</a> <a href="/blog/tags/Elasticsearch/" style="font-size: 0.8em;">Elasticsearch</a> <a href="/blog/tags/Eureka/" style="font-size: 0.8em;">Eureka</a> <a href="/blog/tags/Feign/" style="font-size: 0.8em;">Feign</a> <a href="/blog/tags/Gateway/" style="font-size: 0.8em;">Gateway</a> <a href="/blog/tags/Idea/" style="font-size: 0.8em;">Idea</a> <a href="/blog/tags/Java/" style="font-size: 0.8em;">Java</a> <a href="/blog/tags/JavaWeb/" style="font-size: 0.8em;">JavaWeb</a> <a href="/blog/tags/Linux/" style="font-size: 0.8em;">Linux</a> <a href="/blog/tags/Maven/" style="font-size: 0.8em;">Maven</a> <a href="/blog/tags/MySQL/" style="font-size: 0.8em;">MySQL</a> <a href="/blog/tags/Mybatis/" style="font-size: 0.8em;">Mybatis</a> <a href="/blog/tags/Nacos/" style="font-size: 0.8em;">Nacos</a> <a href="/blog/tags/Pytest/" style="font-size: 0.8em;">Pytest</a> <a href="/blog/tags/Python/" style="font-size: 0.8em;">Python</a>
      </div>
  </aside>

            
                
  <aside id="krw-posts" class="widget widget-kratos-posts">
  <h4 class="widget-title"><i class="fa fa-file"></i>最新文章</h4>
  <div class="tab-content">
      <ul class="list-group">
        
        
          
          
            <a class="list-group-item" href="/blog/2024/04/07/Java%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6/Java%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6/"><i class="fa  fa-book"></i> 【Java】常见的日志框架</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/06/SpringCloud/ElasticStack/Elasticsearch%E6%90%9C%E7%B4%A2%E8%AF%AD%E6%B3%95/"><i class="fa  fa-book"></i> 【ES】搜索语法</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/03/SpringCloud/ElasticStack/Elasticsearch%E7%B4%A2%E5%BC%95%E9%85%8D%E7%BD%AE/"><i class="fa  fa-book"></i> 【ES】索引配置</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/02/SpringCloud/ElasticStack/Kibana%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD/"><i class="fa  fa-book"></i> 【Kibana】常用功能</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/02/SpringCloud/ElasticStack/IK%E5%88%86%E8%AF%8D%E5%99%A8/"><i class="fa  fa-book"></i> 【IK 分词器】基本使用</a>
            
          
        
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
      </ul>
  </div>
  </aside>

            
    </div>
</section>
        
        </div>
    </div>
</div>
<footer>
    <div id="footer"  >
        <div class="container">
            <div class="row">
                <div class="col-md-6 col-md-offset-3 footer-list text-center">
                    <ul class="kratos-social-icons">
                        <!-- Keep for compatibility -->
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        <!-- New links -->
                        
                    </ul>
                    <ul class="kratos-copyright">
                        <div>
                            <li>&copy; 2025 溪岚花的博客 版权所有.</li>
                            <li>本站已运行<span id="span_dt">Loading...</span></li>
                        </div>
                        <div>
                            <li>Theme <a href="https://github.com/Candinya/Kratos-Rebirth" target="_blank">Kratos:Rebirth</a></li>
                            <li>Site built with&nbsp;<i class="fa fa-heart throb" style="color:#d43f57"></i>&nbsp;by 林家隆.</li>
                        </div>
                        <div>
                            <li>Powered by <a href="https://hexo.io" target="_blank" rel="nofollow">Hexo</a></li>
                            <li>Hosted on <a href="https://gitee.com/" target="_blank">Gitee Pages</a></li>
                        </div>
                        <div>
                            
                            
                        </div>
                    </ul>
                </div>
            </div>
        </div>
        <div class="kr-tool text-center">
            <div class="tool">
                
                    <div class="box search-box">
                        <a href="/blog/search/">
                            <span class="fa fa-search"></span>
                        </a>
                    </div>
                
                
                    <div class="box theme-box" id="darkmode-switch">
                        <span class="fa fa-adjust"></span>
                    </div>
                
                
                
            </div>
            <div class="box gotop-box">
                <span class="fa fa-chevron-up"></span>
            </div>
        </div>
    </div>
</footer>
</div>
</div>

        <script defer src="/blog/vendors/bootstrap@3.3.4/dist/js/bootstrap.min.js"></script>
<script defer src="/blog/vendors/nprogress@0.2.0/nprogress.js"></script>
<script>
    if (!window.kr) {
        window.kr = {};
    }
    window.kr.notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));
    window.kr.siteRoot = "/blog/";
</script>





    <script defer src="/blog/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

<script defer src="/blog/js/kratosr.min.js"></script>
<script defer src="/blog/js/pjax.min.js"></script>



<!-- Extra support for third-party plguins  -->


    </body>
</html>